package cn.stylefeng.guns.modular.system.service.ActivityEvent;

import cn.stylefeng.guns.modular.system.entity.AfterIndentCommit;
import cn.stylefeng.guns.modular.system.service.AfterIndentCommitService;
import cn.stylefeng.guns.sys.core.util.utility.StatusCode;
import cn.stylefeng.roses.core.util.SpringContextHolder;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.activiti.engine.delegate.DelegateExecution;
import org.activiti.engine.delegate.ExecutionListener;

/**申请售后单监听
 * @Author : xiaofei
 * @Date: 2019/7/29
 */
public class AfterSaleCommitEvent implements ExecutionListener {

    private AfterIndentCommitService afterIndentCommitService = SpringContextHolder.getBean(AfterIndentCommitService.class);

    @Override
    public void notify(DelegateExecution delegateExecution) {

        String eventName = delegateExecution.getEventName();
        AfterIndentCommit afterIndentCommit = afterIndentCommitService.getOne(new QueryWrapper<AfterIndentCommit>()
                .lambda().eq(AfterIndentCommit::getProessInstanceId,delegateExecution.getProcessInstanceId()));
        if ("end".equals(eventName)){
            afterIndentCommit.setCheckStatus(StatusCode.FAIL.getVal());
        }else if ("start".equals(eventName)){
            afterIndentCommit.setCheckStatus(StatusCode.SUCCESS.getVal());
        }
        afterIndentCommitService.getBaseMapper().updateById(afterIndentCommit);
    }
}
